package org.erp.product.controller;

import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.erp.common.domain.Result;
import org.erp.common.page.DataPageResp;
import org.erp.common.page.PageQueryModel;
import org.erp.product.domain.bo.RepairActionBo;
import org.erp.product.domain.bo.RepairInfoQueryBo;
import org.erp.product.domain.vo.RepairInfoVo;
import org.erp.product.infrastructure.convert.RepairInfoConvert;
import org.erp.product.router.RepairActionFacade;
import org.erp.product.service.RepairInfoService;
import org.springframework.web.bind.annotation.*;

import static org.erp.common.domain.Result.success;

/**
 * @author libin
 * @version 1.0
 * @description:
 * @date 2025/11/26 22:39
 **/
@Log4j2
@RestController
@AllArgsConstructor
@RequestMapping("/repair")
public class RepairInfoController {

    private final RepairInfoService repairInfoService;

    private final RepairActionFacade repairActionFacade;

    private final RepairInfoConvert repairInfoConvert;

    /**
     * 维修列表
     *
     * @param repairInfoQueryBo
     * @return
     */
    @PostMapping("/list")
    public Result<DataPageResp<RepairInfoVo>> pageList(@RequestBody RepairInfoQueryBo repairInfoQueryBo) {
        PageQueryModel<RepairInfoVo> pageList = repairInfoService.pageList(repairInfoConvert.boConvertDto(repairInfoQueryBo));
        return success(DataPageResp.of(pageList.getTotal(), pageList.getDataList()));
    }


    @PutMapping("/action")
    public Result<String> action(@RequestBody RepairActionBo repairActionBo) {
        repairActionFacade.action(repairInfoConvert.boConvertDto(repairActionBo));
        return success();
    }

}
